<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>BigInt类型</title>
  </head>
  <body>
    <script>
      // 大整型
      let n = 123n;
      console.log(n, typeof n); // 123n 'bigint'

      // 函数  将普通的整数转换为大整型
      let n1 = 123;
      console.log(BigInt(n1)); //123n

      // 作用：用于大数值的运算
      let max = Number.MAX_SAFE_INTEGER; // 最大值
      console.log(max);
      console.log(max + 1);
      console.log(max + 2); // 超出范围计算错误

      console.log(BigInt(max)); // 借助BigInt计算
      console.log(BigInt(max) + BigInt(1));
      console.log(BigInt(max) + BigInt(10));
    </script>
  </body>
</html>
